<template>
  <div class="container-y">
    <ul class="contacts-ul">
      <li class="contacts-li"
          v-for="item in list">
        <input class="checkInput"
               :value="item"
               type="checkbox"
               v-model="checked">
        <div class="txtWrap">
          <div class="name nameOnly">
            {{item.text}}
          </div>
          <div class="checkIcon"></div>
        </div>
      </li>
    </ul>
    <div class="pdb"></div>
  </div>
</template>

<script>
  const headerFlag = 140;

  export default {
    data() {
      return {
        type: false,
        list: [],
        checked: [],
        rc: [],
        ic: [],
        lastFlag: {},
      }
    },
    methods: {
      init() {
        this.type = _methods.getUrlParam("type") - 0;
        this.lastFlag = this.$store.state.headerRightType;
        _methods.headerTitleChange(headerFlag + this.type);
        _methods.headerRightShow({
          txt: "选择",
          val: headerFlag,
        });
        this.list = ["", window.regionData, window.industryData][this.type];
        this.setChecked();
      },
      getChecked() {
        let dt = {
          text: "",
          id: []
        };
        let ids = [];
        dt.text = this.checked.map((i) => {
          ids.push(i.id);
          return i.text;
        }).join(",");
        dt.id = ids;
        if (this.type === 1) {
          this.rc = this.checked;
          dt.text = dt.text ? dt.text : "点击选择地域";
          this.$store.commit("_regionDataChecked", dt);
        } else {
          this.ic = this.checked;
          dt.text = dt.text ? dt.text : "点击选择行业";
          this.$store.commit("_industryDataChecked", dt);
        }
      },
      setChecked() {
        if (_data.isRegionDraft) {
          if (this.type === 1) {
            this.rc = _data.isRegionStore.rc;
          } else {
            this.ic = _data.isRegionStore.ic;
          }

          _data.isRegionDraft = false;
        }

        let checkedData = ["", this.rc, this.ic][this.type];

        this.checked = checkedData;


      },
    },
    mounted() {
      this.init();
      _data.busInit.on_(() => {
        this.getChecked();
        _methods.goBack();
      });
    },
    beforeDestroy() {
      _data.busInit.off_();
      _methods.headerTitleChange(14, true);
      _methods.headerRightShow(this.lastFlag);
    }
  }
</script>

